﻿//-----------------------------------------------------------------------
//<copyright file="ReportDAO.cs
//Code generate by tools.
//</copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using PMS.Exceptions;
using System.Data.SqlClient;
using PMS.Entity;

namespace PMS.DAL
{
    public class ReportDAO : SQLDatabase, PMS.DAL.IReportDAO
    {
        public DataSet PhiepNhapKhoReport(string MaPN)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spPhieuNhapGetForPrinting");

                AddInParameter(command, "@SoPN", SqlDbType.NVarChar, MaPN);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhieuNhapGetForPrinting Exception", ex);
            }
        }

        public DataSet PhiepXuatKhoReport(string SoPX)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spPhieuXuatGetForPrinting");

                AddInParameter(command, "@SoPX", SqlDbType.NVarChar, SoPX);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhieuNhapGetForPrinting Exception", ex);
            }
        }

        public DataSet PhiepGiaoHangKhoReport(string SoPG)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spPhieuGiaoHangGetForPrinting");

                AddInParameter(command, "@SoPG", SqlDbType.NVarChar, SoPG);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }

        public DataSet BaoCaoSanPhamKhachHangDaMua(string KhachHang, DateTime? tungay, DateTime? denngay)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("BaoCaoSanPhamKhachHangDaMua");

                AddInParameter(command, "@MaKhahHang", SqlDbType.NVarChar, KhachHang);
                AddInParameter(command, "@TuNgay", SqlDbType.DateTime, tungay);
                AddInParameter(command, "@DenNgay", SqlDbType.DateTime, denngay);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }

        public DataSet BaoCaoCacKhachHangDaMuaSanPham(string masanpham, DateTime? tungay, DateTime? denngay)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("BaoCaoCacKhachHangDaMuaSanPham");

                AddInParameter(command, "@MaSanPham", SqlDbType.NVarChar, masanpham);
                AddInParameter(command, "@TuNgay", SqlDbType.DateTime, tungay);
                AddInParameter(command, "@DenNgay", SqlDbType.DateTime, denngay);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }

        public DataSet BaoCaoDoanhThuCuaSanPham(string masanpham, DateTime? tungay, DateTime? denngay)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("sBaoCaoDoanhThuCuaSanPham");

                AddInParameter(command, "@MaSanPham", SqlDbType.NVarChar, masanpham);
                AddInParameter(command, "@TuNgay", SqlDbType.DateTime, tungay);
                AddInParameter(command, "@DenNgay", SqlDbType.DateTime, denngay);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }

        public DataSet BaoCaoCongNoCuaKhachHang(string MaKhachHang, DateTime? tungay, DateTime? denngay)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("BaoCaoCongNoCuaKhachHang");

                AddInParameter(command, "@MaKhachHang", SqlDbType.NVarChar, MaKhachHang);
                AddInParameter(command, "@TuNgay", SqlDbType.DateTime, tungay);
                AddInParameter(command, "@DenNgay", SqlDbType.DateTime, denngay);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }


        public DataSet TheKho(string MaThuoc,String Solo)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spBaoCaoTheoKho");

                AddInParameter(command, "@MaThuoc", SqlDbType.NVarChar, MaThuoc);
                AddInParameter(command, "@SoLo", SqlDbType.NVarChar, Solo);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }

        public DataSet BienBanNhapHangReport(string MaBBNH)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanNhapHangGetForPrint");

                AddInParameter(command, "@MaBBNH", SqlDbType.NVarChar, MaBBNH);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }

        public DataSet BienBanKiemKeKhoReport(string MaBBKKK)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanKiemKeKhoGetForPrint");

                AddInParameter(command, "@MaBBKKK", SqlDbType.NVarChar, MaBBKKK);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }

        public DataSet BaoCaoXuatNhapTonReport(string MaKy)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spBaoCaoXuatNhapTonGetForPrint");

                AddInParameter(command, "@MaKy", SqlDbType.NVarChar, MaKy);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }

        public DataSet SanPhamListReport()
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spGetSanPhamListForPrint");
                
                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access SanPhamReport Exception", ex);
            }
        }

        public DataSet KhachHangListReport()
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spGetKhachHangListForPrint");

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access KhachHangReport Exception", ex);
            }
        }

        public DataSet NhaCCListReport()
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spGetNhaCCListForPrint");

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access NhaCCReport Exception", ex);
            }
        }

        public DataSet ChiTietNhapSanPham(string MaSP, DateTime? tungay, DateTime? denngay)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietNhapSanPham");

                AddInParameter(command, "@masp", SqlDbType.NVarChar, MaSP);
                AddInParameter(command, "@tungay", SqlDbType.DateTime, tungay);
                AddInParameter(command, "@denngay", SqlDbType.DateTime, denngay);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }
        }

        public DataSet ChiTietXuatSanPham(string MaSP, DateTime? tungay, DateTime? denngay)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietXuatSanPham");

                AddInParameter(command, "@masp", SqlDbType.NVarChar, MaSP);
                AddInParameter(command, "@tungay", SqlDbType.DateTime, tungay);
                AddInParameter(command, "@denngay", SqlDbType.DateTime, denngay);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access PhiepGiaoHangKhoReport Exception", ex);
            }            
        }

        public DataSet TheKhoByDate(string MaThuoc, String Solo, DateTime? tungay, DateTime? denngay)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spBaoCaoTheKhoByDate");

                AddInParameter(command, "@MaThuoc", SqlDbType.NVarChar, MaThuoc);
                AddInParameter(command, "@SoLo", SqlDbType.NVarChar, Solo);
                AddInParameter(command, "@tungay", SqlDbType.DateTime, tungay);
                AddInParameter(command, "@denngay", SqlDbType.DateTime, denngay);

                return ExecuteToDataset(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access TheKhoByDateReport Exception", ex);
            }            
        }
    }
}
